package com.talkology.pilot.student.controller;

import com.talkology.pilot.database.model.TalkSalonBooking;
import com.talkology.pilot.student.model.SalonBookingRest;
import com.talkology.pilot.student.service.ISalonBookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/salonBookings")
public class SalonBookingController {
    @Autowired
    private ISalonBookingService salonBookingService;

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @ResponseBody
    public List<TalkSalonBooking> getSalongBookingsByFilter
            (@RequestParam(value = "talkSalonName", required = false) String talkSalonName,
             @RequestParam(value = "studentId", required = false) String studentId,
             @RequestParam(value = "teacherName", required = false) String teacherName,
             @RequestParam(value = "classBegin", required = false) String classBegin,
             @RequestParam(value = "classEnd", required = false) String classEnd,
             @RequestParam(value = "status", required = false) String status) {
        return salonBookingService.getAllByFilter(talkSalonName, studentId, teacherName, classBegin, classEnd, status);
    }

    @RequestMapping(value = "/book", method = RequestMethod.POST)
    @ResponseBody
    public void addSalonBookings(@RequestBody SalonBookingRest rest) {
        salonBookingService.addSalonBookings(rest);
    }

    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ResponseBody
    public void updateSalonBookings(@RequestBody TalkSalonBooking rest) {
        salonBookingService.editSalonBookings(rest);
    }

    @RequestMapping(value = "/cancel", method = RequestMethod.POST)
    @ResponseBody
    public void cancelSalonBooking(@RequestParam(value = "talkSalonName", required = true) String talkSalonName,
                                   @RequestParam(value = "studentId", required = true) String studentId,
                                   @RequestBody List<String> timeItems) {
        salonBookingService.cancel(talkSalonName, studentId, timeItems);
    }

}
